home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Messaging Service Access Module / Internet PMSAM / Internet PMSAM source / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-23  |  3.3 KB  |  197 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------
  2.  
  3. AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
  4. Mail Service Access Module
  5.  
  6. written by Steve Falkenburg-- MacDTS
  7. ©1991-1993 Apple Computer, Inc.
  8.  
  9. --------------
  10. change history
  11. --------------
  12.  
  13. SJF        02/19/93    update for beta build    b1
  14. SJF        10/29/92    update to a11            a11
  15. SJF        06/08/92    update to a8            a8
  16. SJF        02/15/92    first working version    a4.5
  17. SJF        10/16/91    initial coding            a3
  18.  
  19. ---------------------------------------------------------------------*/
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24.  
  25. #ifndef __GESTALTEQU__
  26. #include <GestaltEqu.h>
  27. #endif
  28.  
  29. #ifndef __TRAPS__
  30. #include <Traps.h>
  31. #endif
  32.  
  33. #ifndef __PACKAGES__
  34. #include <Packages.h>
  35. #endif
  36.  
  37. #ifndef _GestaltDispatch
  38. #define    _GestaltDispatch    _Gestalt
  39. #endif
  40.  
  41. #include "const.h"
  42. #include "mytypes.h"
  43. #include "gwerrors.h"
  44. #include "globals.h"
  45. #include "trapavailable.h"
  46. #include "main.h"
  47. #include "utils.h"
  48.  
  49. Boolean SupportsAEVT(void)
  50. {
  51.     OSErr err;
  52.     long response;
  53.     
  54.     if (!TrapAvailable(_GestaltDispatch))
  55.         return false;
  56.     
  57.     err = Gestalt(gestaltAppleEventsAttr,&response);
  58.     if (err!=noErr)
  59.         return false;
  60.         
  61.     return (response && (response << gestaltAppleEventsPresent));
  62. }
  63.  
  64.  
  65. void pstrcpy(void *dest,void *src)
  66. {
  67.     unsigned char srcLen = ((unsigned char *)src)[0];
  68.     
  69.     BlockMove(src,dest,srcLen+1);
  70. }
  71.  
  72.  
  73. void pstrcat(void *original,void *catStr)
  74. {
  75.     short length;
  76.     unsigned char originalLen = ((unsigned char *)original)[0];
  77.     unsigned char catStrLen = ((unsigned char *)catStr)[0];
  78.     
  79.     length = (short) originalLen;
  80.     length += (short) catStrLen;
  81.  
  82. #ifdef kDEBUG    
  83.     if (length > 255) {
  84.         DebugStr("\pstring catenation overflow");
  85.         ExitProc();
  86.     }
  87. #endif
  88.     
  89.     BlockMove((char *)catStr+1,(char *)original+originalLen+1,catStrLen);
  90.     ((unsigned char *)original)[0] = (unsigned char) length;
  91. }
  92.  
  93.  
  94. void *NewPtrChk(Size ptrSize)
  95. {
  96.     Ptr thePtr;
  97.  
  98.     thePtr = NewPtr(ptrSize);
  99.     if (MemError()!=noErr)
  100.         DoError(MemError());
  101. #if kDEBUG
  102.     {
  103.         long *longPtr = (long *)thePtr;
  104.         *longPtr = kBetterBusErr;
  105.     }
  106. #endif
  107.     return thePtr;
  108. }
  109.  
  110.  
  111. void *NewHandleChk(Size hndlSize)
  112. {
  113.     Handle theHndl;
  114.     
  115.     theHndl = NewHandle(hndlSize);
  116.     if (MemError()!=noErr)
  117.         DoError(MemError());
  118. #if kDEBUG
  119.     {
  120.         long **longHndl = (long **)theHndl;
  121.         **longHndl = kBetterBusErr;
  122.     }
  123. #endif
  124.     return theHndl;
  125. }
  126.  
  127.  
  128. void DisposPtrChk(void *thePtr)
  129. {
  130. #if kDEBUG
  131.     {
  132.         long *longPtr = (long *)thePtr;
  133.         *longPtr = kBetterBusErr;
  134.     }
  135. #endif
  136.  
  137.     DisposPtr(thePtr);
  138.     if (MemError()!=noErr)
  139.         DoError(MemError());
  140. }
  141.  
  142.  
  143. void DisposHandleChk(void *theHndl)
  144. {
  145. #if kDEBUG
  146.     {
  147.         long **longHndl = (long **)theHndl;
  148.         **longHndl = kBetterBusErr;
  149.     }
  150. #endif
  151.  
  152.     DisposHandle(theHndl);
  153.     if (MemError()!=noErr)
  154.         DoError(MemError());
  155. }
  156.  
  157.  
  158. OSErr WaitPBDone(void *voidBlock)
  159. {
  160.     IOParam *pBlock;
  161. #ifdef kDEBUG
  162.     Str255 errStr;
  163. #endif
  164.     
  165.     pBlock = (IOParam *)voidBlock;
  166.     
  167.     if (gWakeUpSecondary==false) {
  168.         while (pBlock->ioResult == 1)
  169.             SecondaryEventLoop();
  170.         while (gWakeUpSecondary==false)
  171.             ;
  172.     }
  173.     
  174.     gWakeUpSecondary = false;    // set to false for next invocation
  175.  
  176. #ifdef kDEBUG
  177.     if (pBlock->ioResult!=noErr) {
  178.         NumToString(pBlock->ioResult,errStr);
  179.         pstrcat(errStr,"\p ******** ERROR ********");
  180.         DebugStr(errStr);
  181.     }
  182. #endif
  183.     
  184.     return pBlock->ioResult;
  185. }
  186.  
  187.  
  188. void ClearBuffer(void *buff,Size length)
  189. {
  190.     unsigned long index;
  191.     char *clrBuff;
  192.     
  193.     clrBuff = (char *)buff;
  194.     for (index=0; index<length; index++)
  195.         clrBuff[index] = 0;
  196. }
  197.